package com.QBsoft.commons.factory;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.QBsoft.spring.service.IWsService;
/**
 * 
 * @author aquingaluisa
 * 
 */
public class WsFactory {
	private static final WsFactory instancia = new WsFactory();
	private ApplicationContext context=activateFactory();
	public WsFactory() {
		try{
			context = new ClassPathXmlApplicationContext(new String[]{
					WsFactoryConstants.GESTOR_CONTEXTPATH,
					WsFactoryConstants.SERVICES_CONTEXTPATH,
			});
		}
		catch(Exception e){
			
		}
	}
	private static ApplicationContext activateFactory(){
		try{
			return new ClassPathXmlApplicationContext(new String[]{
					WsFactoryConstants.GESTOR_CONTEXTPATH,
					WsFactoryConstants.SERVICES_CONTEXTPATH,
			});
		}
		catch(Exception e){
			System.out.println("Error al crear el contenedor de spring:"+e);
			throw new RuntimeException(e);
		}
		
	}
	public static WsFactory getInstancia() {
		return instancia;
	}
	/**
	 * Instancia Servicio de seguridades
	 * @return
	 * @throws FrameworkException
	 */
	public IWsService getWsService()throws Exception{
		return context.getBean(WsFactoryConstants.WS_SERVICE,IWsService.class);
		
	}
	public  Object getBean(String bean) throws Exception {
		return context.getBean(bean);
	}
}
